package com.lovo.sqlatm;

import com.lovo.fileUtil.FileUtil;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class Menu extends JPanel implements ActionListener {
    private Icon save = Util.getIcon("/img/buttonSave.jpg");
    private Icon get = Util.getIcon("/img/buttonGet.jpg");
    private Icon find = Util.getIcon("/img/buttonFind.jpg");
    private Icon modify = Util.getIcon("/img/buttonModify.jpg");
    private Icon transfer= Util.getIcon("/img/pane.jpg");
    private Icon out = Util.getIcon("/img/buttonOff.jpg");


    private Test0 frame;
    private  JButton outButton;
    private JButton lnquireButton;
    private JButton saveButton;
    private JButton tellerButton;
    private JButton reviseButton;
    private JButton transferButton;


         public Menu(Test0 frame){
             this.frame=frame;
             this.setLayout(null);
             //欢迎词

             JLabel jLabel =new JLabel("欢迎你");

             jLabel.setBounds(123,120,100,30);
             this.add(jLabel);
             //存
             saveButton =new JButton(save);
             saveButton.setBounds(124,468,140,50);
             saveButton.addActionListener(this);
             this.add(saveButton);

             //取
              tellerButton =new JButton(get);
             tellerButton.setBounds(284,468,140,50);
             tellerButton.addActionListener(this);
             this.add(tellerButton);
             //查
             lnquireButton =new JButton(find);
             lnquireButton.setBounds(444,468,140,50);
             lnquireButton.addActionListener(this);
             this.add(lnquireButton);

             //改
             reviseButton =new JButton(modify);
             reviseButton.setBounds(604,468,140,50);
             reviseButton.addActionListener(this);
             this.add(reviseButton);


             //转账
              transferButton =new JButton(transfer);
             transferButton.setBounds(284,568,140,50);
             transferButton.addActionListener(this);
             this.add(transferButton);
             //退
             outButton =new JButton(out);
             outButton.setBounds(444,568,140,50);
             outButton.addActionListener(this);
             this.add(outButton);

             this.setOpaque(false);
         }
    @Override
    public void actionPerformed(ActionEvent e) {
             if (e.getSource()==outButton){
                 frame.switchPanel("login");
             }else if (e.getSource()==lnquireButton){



                 frame.getLnquire().getLabel().setText("你的余额为:"+frame.getUesr().getBalance()+"");
                 String account =frame.getUesr().getAccount();
                 String password =frame.getUesr().getPassword();
                 int balan =frame.getUesr().getBalance();
                 Test01.update(account,password,balan);

                 frame.switchPanel("lnquire");

             }else if (e.getSource()==saveButton){

                 frame.switchPanel("save");
                 FileUtil.writeObject("d:/b/login.dzt",frame.getUesr());
             }else if (e.getSource()==tellerButton){
                 frame.switchPanel("teller");
                 FileUtil.writeObject("d:/b/login.dzt",frame.getUesr());
             }else if (e.getSource()==reviseButton){
                 frame.switchPanel("revise");
                 FileUtil.writeObject("d:/b/login.dzt",frame.getUesr());
             }else if (e.getSource()==transferButton){
                 frame.switchPanel("transfer");
                 FileUtil.writeObject("d:/b/login.dzt",frame.getUesr());
             }


    }
}
